package com.cskaoyan.user.controller;

import com.cskaoyan.mall.commons.constant.SysRetCodeConstants;
import com.cskaoyan.mall.commons.result.ResponseData;
import com.cskaoyan.user.dto.UserVerifyRequest;
import com.cskaoyan.user.dto.UserVerifyResponse;
import com.cskaoyan.user.service.IRegisterVerifyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * http://localhost:8080/user/verify?uid=xxx&username=xxx
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class RegisterVerifyController {
    @Autowired
    IRegisterVerifyService iRegisterVerifyService;
    @GetMapping("/verify")
    public ResponseData registerVerify(@RequestParam Map<String,Object>map){

        String uid = (String) map.get("uid");
        String username = (String) map.get("username");
        UserVerifyRequest userVerifyRequest = new UserVerifyRequest();
        userVerifyRequest.setUserName(username);
        userVerifyRequest.setUuid(uid);
        UserVerifyResponse userVerifyResponse=
        iRegisterVerifyService.verify(userVerifyRequest);
        if (userVerifyResponse.getCode().equals(SysRetCodeConstants.SUCCESS.getCode())){
            return ResponseData.successNoResult();
        }
        return ResponseData.msg(userVerifyResponse.getMsg());
    }
}
